#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
int main()
{
    pid_t id = fork();
    if(id==0)
    {
        int k=5;
        while(k--) printf("子进程执行中,pid=%d\n",getpid()),sleep(1);
        exit(10);
    }
    
    //pid_t p = waitpid(id,NULL,0);
    //pid_t p=wait(NULL);
    int st;
    pid_t p=waitpid(id,&st,0);
    if(p>0)
    {
        if(st==0) printf("子进程正常退出\n");
        else printf("子进程执行错误,错误码：%d\n",(st>>8)&0xFF);
    }
    else if(p==0) printf("wait错误\n");
    else printf("子进程异常退出\n");
    printf("父进程退出\n");
    return 0;
}
